package blockencryption;

import general.Utility;

import javax.crypto.BadPaddingException;

public class BlockCipherer {

	/**
	 * takes a bunch of data, divides it into blocks, calls Encryptor.cipher()
	 * on each block to en-/decrypt it and merges the blocks together again
	 */
	static int[] blockCipher(byte[] key, int[] lineData, boolean encrypt) throws BadPaddingException {
		// original data
		int[][] dataChunks = Utility.splitData(lineData);
		// manipulated data
		int[][] cipheredDataChunks = new int[dataChunks.length][];

		for (int i = 0; i < dataChunks.length; i++) {
			cipheredDataChunks[i] = Encryptor.cipher(dataChunks[i], key, encrypt);
		}
		return Utility.mergeData(cipheredDataChunks);
	}
}
